import request from '@/utils/request'

// 获取错误回答次数最多的题目列表
export function getMostWrongQuestions(questionType, limit) {
  return request({
    url: `/manage/wrongQuestion/mostWrong/${questionType}/${limit}`,
    method: 'get'
  })
}

// 根据难度获取错误回答次数最多的题目列表
export function getMostWrongQuestionsByDifficulty(questionType, difficulty, limit) {
  return request({
    url: `/manage/wrongQuestion/mostWrong/difficulty/${questionType}/${difficulty}/${limit}`,
    method: 'get'
  })
}

// 根据章节获取错误回答次数最多的题目列表
export function getMostWrongQuestionsByChapter(questionType, chapterId, limit) {
  return request({
    url: `/manage/wrongQuestion/mostWrong/chapter/${questionType}/${chapterId}/${limit}`,
    method: 'get'
  })
}

// 获取错题列表（带分页、筛选功能）
export function listWrongQuestions(query) {
  return request({
    url: '/manage/wrongQuestion/list',
    method: 'get',
    params: query
  })
}

// 获取学生个人的错题列表
export function listStudentWrongQuestions(query) {
  return request({
    url: '/manage/wrongQuestion/listByStudent',
    method: 'get',
    params: query
  })
}

// 随机选择学生错题进行组卷
export function randomSelectWrongQuestions(data) {
  // 确保学生信息存在
  if (!data.studentNumber) {
    console.error('缺少学生学号参数');
    return Promise.reject(new Error('缺少学生学号参数'));
  }
  
  return request({
    url: '/manage/wrongQuestion/randomByStudent',
    method: 'post',
    data: data
  })
} 